<template>
  <div>
    <el-dialog
      title="基本信息"
      :visible.sync="dialogVisible"
      width="60%"
      @close="colse"
    >
      <el-form :model="newclazzlist" label-width="80px">
        <el-row :gutter="24">
          <el-col :span="8" :offset="0">
            <el-form-item label="宿舍名字">
              <el-input v-model="newclazzlist.name"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8" :offset="0">
            <el-form-item label="宿舍类型">
              <el-select
                v-model="newclazzlist.type"
                style="width: 100%"
                placeholder="请选择宿舍类型"
              >
                <el-option
                  v-for="item in clazzOption"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8" :offset="0">
            <el-form-item label="宿舍地址">
              <el-input v-model="newclazzlist.position"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24">
          <el-col :span="8" :offset="0">
            <el-form-item label="开班时间">
              <el-date-picker
                v-model="newclazzlist.startTime"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="选择日期时间"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8" :offset="0">
            <el-form-item label="结束时间">
              <el-date-picker
                v-model="newclazzlist.endTime"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="选择日期时间"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8" :offset="0">
            <el-form-item label="班级描述">
              <el-input v-model="newclazzlist.bak"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <span slot="footer">
        <el-button @click="dialogVisible = false">Cancel</el-button>
        <el-button type="primary" @click="add">添加</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>

import ClazzApi from "@/api/clazz/clazz";
export default {
  data() {
    return {
      newclazzlist: {},
      dialogVisible: false,
      clazzOption: [
        {
          label: "男生宿舍",
          value: "0",
        },
        {
          label: "女生宿舍",
          value: "1",
        },
        {
          label: "未定",
          value: "2",
        },
      ],
    };
  },
  created() {},
  methods: {
    opendialogVisible(id) {
      this.dialogVisible = true;
      if (id) {
        ClazzApi.dormdetail({ id }).then((res) => {
          console.log(res, "1111");
          this.newclazzlist = res.data;
        });
      }
    },
    add() {
        var api =null;
        if(this.newclazzlist.id){
            api=ClazzApi.dormupdate
        }else{
            api=ClazzApi.dormsave
        }
      api({
        xyDormInfo: {
          ...this.newclazzlist,
        },
      }).then((res) => {});
      this.dialogVisible = false;
      this.$emit("getclazzlist");
      this.newclazzlist = {};
    },
    onSubmit() {},
    colse() {},
  },
};
</script>
<style scoped  lang='scss'>
</style>